package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.web.admin.mapper.*;
import com.atguigu.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.atguigu.lease.web.admin.vo.agreement.AgreementVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 10740
* @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
* @createDate 2024-06-18 18:20:58
*/
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
    implements LeaseAgreementService{
    @Autowired
    LeaseAgreementMapper agreementMapper;
    @Autowired
    ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    RoomInfoMapper roomInfoMapper;
    @Autowired
    PaymentTypeMapper paymentTypeMapper;
    @Autowired
    LeaseTermMapper leaseTermMapper;

    @Override
    public IPage<AgreementVo> getVoPage(IPage<AgreementVo> voIPage, AgreementQueryVo queryVo) {
        return agreementMapper.getVoPage(voIPage,queryVo);
    }

    @Override
    public AgreementVo getInfoById(Long id) {

        AgreementVo agreementVo = new AgreementVo();

        //根据id查询租约信息
        LeaseAgreement leaseAgreement = getById(id);

        //租约对象中有其它关联表的外键(根据外键把其他表的信息查询出来)
        //公寓
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());

        //房间
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());

        //支付方式
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());

        //租期
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());

        agreementVo.setApartmentInfo(apartmentInfo);
        agreementVo.setRoomInfo(roomInfo);
        agreementVo.setPaymentType(paymentType);
        agreementVo.setLeaseTerm(leaseTerm);

        BeanUtils.copyProperties(leaseAgreement,agreementVo);


        return agreementVo;
    }
}




